package com.android.porttallymansystem.logic.database

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.android.porttallymansystem.logic.dao.MsgDao
import com.android.porttallymansystem.logic.model.Msg

@Database(version = 1, entities = [Msg::class])
abstract class MsgDatabase : RoomDatabase() {

    abstract fun msgDao(): MsgDao

    companion object {

        private var instance: MsgDatabase? = null

        fun getDatabase(context: Context): MsgDatabase {
            instance?.let {
                return it
            }
            return Room.databaseBuilder(
                context.applicationContext,
                MsgDatabase::class.java,
                "msg_database"
            ).build().apply{
                instance = this
            }
        }
    }
}